public class For {
    public static int fac(int n) {
        int num = 1;
        for(int i = 1; i <= n; i++){
            num = num * i;
        }
        return num;
    }
    public static void main1(String[] args) {
        //阶乘求和
        int sum = 0;
        for(int i = 1; i <= 6; i++){
            sum += fac(i);
        }
        System.out.println("6!=" + sum);
    }

    public static void fib(int n) {
        //迭代斐波那契数列
        int num = 0;
        int num1 = 1;
        int num2 = 1;
        for(int i = 0; i < n-2; i++){
            num = num2;
            num2 = num1 + num2;
            num1 = num;
        }
        System.out.println("数列第"+n+"项的值为:"+num2);
    }

    public static void main2(String[] args) {
        fib(10);
    }
    public static int find(int a[]){
        int num = 0;
        int len = a.length;
        for(int i = 0; i < len; i++){
            num ^= a[i];
        }
        return num;
    }

    public static void main(String[] args) {
        //找出现一次的数字
        int a[] = {1,2,3,4,5,4,3,2,1};
        int result = find(a);
        System.out.println("只出现一次的数据为:"+result);
    }
}
